package com.welink.cmp.meatdata.service;


import com.welink.cmp.dao.metadata.dataobject.HostDO;
import com.welink.cmp.dto.metadata.DestroyUpdateCmd;
import com.welink.cmp.dto.metadata.host.*;
import com.welink.cmp.meatdata.command.HostCmdExe;
import com.welink.common.dto.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Host应用服务类
 * 提供Host相关的操作接口
 */
@Service
@Slf4j
public class HostAppService {

    @Autowired
    private HostCmdExe hostCmdExe;

    /**
     * 添加Host
     *
     * @param addCmd 添加Host的命令对象
     * @return 新增Host的ID
     */
    public Long addHost(CreateHostAddCmd addCmd) {
        // check exist
        final HostDO hostDO = hostCmdExe.queryByAssetsId(addCmd.getAssetsId());
        if (hostDO!=null){
            log.info("资产 ID [{}] 已存在 ",addCmd.getAssetsId());
            return hostDO.getId();
        }
        return hostCmdExe.save(addCmd);
    }

    /**
     * 配置Host基础信息
     *
     * @param setupBaseCmd 配置Host基础信息的命令对象
     * @return 配置是否成功
     */
    public Boolean setupHostBase(SetupHostBaseUpdateCmd setupBaseCmd) {
        // 实现配置Host基础信息逻辑
        HostUpdCmd hostUpdCmd = new HostUpdCmd();
        BeanUtils.copyProperties(setupBaseCmd,hostUpdCmd);

        return hostCmdExe.update(hostUpdCmd);
    }

    /**
     * 配置Host网络信息
     *
     * @param setupNetCmd 配置Host网络信息的命令对象
     * @return 配置是否成功
     */
    public Boolean setupHostNet(SetupHostNetUpdateCmd setupNetCmd) {
        // 实现配置Host网络信息逻辑
        HostUpdCmd hostUpdCmd = new HostUpdCmd();
        BeanUtils.copyProperties(setupNetCmd,hostUpdCmd);
        return hostCmdExe.update(hostUpdCmd);
    }

    /**
     * 配置Host物理机房信息
     *
     * @param setupDcCmd 配置Host物理机房信息的命令对象
     * @return 配置是否成功
     */
    public Boolean setupHostDc(SetupHostRackUpdateCmd setupDcCmd) {
        // 实现配置Host物理机房信息逻辑
        HostUpdCmd hostUpdCmd = new HostUpdCmd();
        BeanUtils.copyProperties(setupDcCmd,hostUpdCmd);
        return hostCmdExe.update(hostUpdCmd);
    }

    /**
     * 上架Host
     *
     * @param cmd 上架Host的命令对象
     * @return 上架是否成功
     */
    public Boolean launchHost(LaunchHostUpdateCmd cmd) {
        // 实现略


        return null;
    }

    /**
     * 下架Host
     *
     * @param cmd 下架Host的命令对象
     * @return 下架是否成功
     */
    public Response shutdownHost(ShutdownHostUpdateCmd cmd) {
        // 实现略
        return Response.buildSuccess();
    }

    /**
     * 注销Host
     *
     * @param cmd 注销Host的命令对象
     * @return 注销是否成功
     */
    public Response destroyHost(DestroyUpdateCmd cmd) {

        return Response.buildSuccess();
    }

}